package com.buddies.lottery.utils;

import android.app.Activity;

import com.blankj.utilcode.util.ToastUtils;
import com.buddies.lottery.common.ConfigManager;
import com.facebook.drawee.backends.pipeline.Fresco;

public class AppExitUtils {

    private static AppExitUtils mInstance;

    private AppExitUtils() {

    }

    public static synchronized AppExitUtils getInstance() {
        if (mInstance == null) {
            mInstance = new AppExitUtils();
        }
        return mInstance;
    }

    private long firstClickTime = 0;

    public void onBackPressed(Activity activity) {
        long secondTime = System.currentTimeMillis();
        if (secondTime - firstClickTime > 2000) {
            ToastUtils.showShort("再按一次退出应用...");
            firstClickTime = secondTime;
        } else {
            Fresco.getImagePipeline().clearMemoryCaches();// 清空内存缓存
            if (ConfigManager.getInstance().isLogin()) {
                activity.moveTaskToBack(true);
            } else {
                activity.finish();
            }
        }
    }

}
